<?php
  require_once(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new sccurrencies();

  if (isset($HTTP_GET_VARS['products_id'])) {
    $orders_query = tep_db_query("select p.products_id, p.products_image, p.products_price from " . TABLE_ORDERS_PRODUCTS . " opa, " . TABLE_ORDERS_PRODUCTS . " opb, " . TABLE_ORDERS . " o, " . TABLE_PRODUCTS . " p where opa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and opa.orders_id = opb.orders_id and opb.products_id != '" . (int)$HTTP_GET_VARS['products_id'] . "' and opb.products_id = p.products_id and opb.orders_id = o.orders_id and p.products_status = '1' group by p.products_id order by o.date_purchased desc limit " . MAX_DISPLAY_ALSO_PURCHASED);
    $num_products_ordered = tep_db_num_rows($orders_query);
    if ($num_products_ordered >= MIN_DISPLAY_ALSO_PURCHASED) {
?>
<!-- also_purchased_products //-->
<tr>
    <td>
    <div class="category_title">
        <div class="lblTitle">Sản phẩm liên quan</div>                      
    </div><br /><br /><br />
    </td>
</tr>
<?php
      /**
 * $info_box_contents = array();
 *       $info_box_contents[] = array('text' => TEXT_ALSO_PURCHASED_PRODUCTS);

 *       new contentBoxHeading($info_box_contents);
 */
        
      $row = 0;
      $col = 0;
      $info_box_contents = array();
      while ($orders = tep_db_fetch_array($orders_query)) {
        $orders['products_name'] = tep_get_products_name($orders['products_id']);
        //echo $currencies->display_price($orders['products_price'], tep_get_tax_rate($orders['products_tax_class_id']));
        $info_box_contents[$row][$col] = array('align' => 'center',
                                               //'params' => 'class="smallText" width="33%" valign="top"',
                                               'text' => '<div class="productlike"><div class="productlike-thumb"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '" title="'.$orders['products_name'].'">' . tep_image(DIR_WS_IMAGES . $orders['products_image'], $orders['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></div><div align="center"><a href="'.tep_href_link('index.php', 'action=buy_now&products_id=' . $orders['products_id']).'">'.tep_image_button('button_in_cart.gif', 'Thêm vào giỏ','class="proceedbtn"').'</a></div><div class="productlike-price">'. $currencies->display_price($orders['products_price'], tep_get_tax_rate($orders['products_tax_class_id'])) .'</div><div class="productlike-tit"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '" title="'.$orders['products_name'].'">' . $orders['products_name'] . '</a></div></div>');
        
        ?>
            
        <?php
        $col ++;
        if ($col > 2) {
          $col = 0;
          $row ++;
        }
      }

      new contentBox($info_box_contents);
?>

<!-- also_purchased_products_eof //-->
<?php
    }
  }
?>
